// ignore_for_file: file_names, must_be_immutable, constant_identifier_names, slash_for_doc_comments, avoid_unnecessary_containers, prefer_const_constructors, unnecessary_cast, sized_box_for_whitespace, prefer_function_declarations_over_variables, overridden_fields, annotate_overrides, prefer_const_literals_to_create_immutables, unnecessary_null_comparison, deprecated_member_use

import 'package:flutter/material.dart';
import 'package:mybase/base/tool/globalMethod/FFSafeValue.dart';

typedef FFNotifier = ValueNotifier<FFNotifierVo>;

class FFProgressManager {
  // 单例公开访问点
  factory FFProgressManager() => _sharedInstance();

  // 静态、同步、私有访问点
  static FFProgressManager _sharedInstance() {
    return _instance;
  }

  // 静态私有成员，没有初始化
  static final FFProgressManager _instance = FFProgressManager._();

  // 私有构造函数
  FFProgressManager._() {
    // 具体初始化代码
  }

  Map<String, FFNotifier> map = {};

  setValueNotifier(String transferId, FFNotifier value) {
    if (map.containsKey(transferId)) {
      return;
    }
    map[transferId] = value;
  }

  FFNotifier? getValueNotifier(String transferId) {
    return globalSafeValueFromMap<FFNotifier>(map, transferId);
  }

// 赋值操作
// var notifier = FFProgressManager().getValueNotifier("0");
// notifier?.value = FFNotifierVo(
// type: FFNotifierVoType.progress,
// percent: progress,
// );
}

class FFNotifierVo {
  // 状态
  FFNotifierVoType type;

  // 进度
  double? percent;
  int? totalNum;
  int? finishNum;

  FFNotifierVo({
    required this.type,
    this.totalNum,
    this.finishNum,
    this.percent,
  });

  setPercent(double p) {
    if (p > 1.0) {
      percent = 1.0;
      return;
    }
    if (p < 0) {
      percent = 0.0;
      return;
    }

    percent = p;
  }

  double getPercent() {
    return percent ?? 0.0;
  }
}

enum FFNotifierVoType {
  // 进度中
  progress,
  // 错误了
  error,
  // 完成了
  finish,
  // 空闲状态
  none,
}
